import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-11-29
 */
public class Test {

    @org.junit.Test
    public void testToString() {
        StringBuilder sb = new StringBuilder("select * from  good");
        String s = sb.substring(sb.indexOf("from"), sb.length());
        System.out.println(s);
    }

    @org.junit.Test
    public void testCalender() {
        Calendar today = Calendar.getInstance();
        today.set(Calendar.HOUR_OF_DAY, 0);
        today.set(Calendar.MINUTE, 0);
        today.set(Calendar.SECOND, 0);
        today.set(Calendar.MILLISECOND, 0);
        today.set(Calendar.DAY_OF_WEEK, -5);
        SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(df2.format(today.getTime()));
        System.out.println(getMondayOfThisWeek(today.getTime()));
    }

    public static String getMondayOfThisWeek(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (day_of_week == 0)
            day_of_week = 7;
        c.add(Calendar.DATE, -day_of_week + 1);
        SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df2.format(c.getTime());
    }

    @org.junit.Test
    public void listAddAllNull() {
        List<String> abc = new ArrayList<>();
        abc.add("hello");
        List<String> bc = null;
        // 会空指针
        abc.addAll(bc);

    }

    @org.junit.Test
    public void test111() {
        System.out.println("rm-pz5048i5li6l7ur8i.mysql.rds.aliyuncs.com".equals("rm-pz5048i5li6l7ur8i.mysql.rds.aliyuncs.com"));
    }

    @org.junit.Test
    public void testListAdd() {
        List<String> strs = new ArrayList<>();
        strs.add("2");
        strs.add("3");

        strs.add(0, "1");
        strs.add("4");

        strs.forEach(s -> System.out.println(s));
    }

    @org.junit.Test
    public void formatConversion() throws IOException {
        File file = new File("C:\\Users\\1\\Desktop\\新建文本文档.txt");

        File format = new File("C:\\Users\\1\\Desktop\\111.txt");

        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(format)));

        String line = reader.readLine();
        while (line != null && !"".equals(line)) {
            line = line.replaceAll("=", "");
            line = "|" + line;
            String[] items = line.split("\\s");
            StringBuilder sb = new StringBuilder();
            for (String item : items) {
                if (null == item || "".equals(item)) {
                    continue;
                }
                sb.append(item).append("|");
            }
            sb.append(System.getProperty("line.separator"));
            writer.append(sb);
            line = reader.readLine();
        }
        writer.flush();
        writer.close();
        reader.close();
    }

}
